package com.ninthgroup.service.Impl;

import com.ninthgroup.entity.Dept;
import com.ninthgroup.mapper.DeptMapper;
import com.ninthgroup.service.DeptService;
import com.ninthgroup.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Student A Wei
 * @date ：Created in 2022/10/14 19:42
 * @description：部门管理接口的实现类
 * @modified By：
 * @version:
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    //查询部门
    @Override
    public Result selectAll(String deptName,Integer deptStatus) {
        List<Dept> depts = deptMapper.selectByCondition(deptName,deptStatus);
        System.out.println("depts = " + depts);
        return new Result(200, "查询成功",depts);
    }

    //添加部门
    @Override
    public Result insertAdd(Dept dept) {
        int insert = deptMapper.insert(dept);
        return new Result(200, "添加成功");
    }

    //删除部门
    @Override
    public Result deleteBydeptId(Integer deptId) {
        int delete = deptMapper.deleteByPrimaryKey(deptId);
        return new Result(200, "删除成功");
    }

    //修改部门
    @Override
    public Result update(Dept dept) {
        int update = deptMapper.updateByPrimaryKey(dept);
        return new Result(200,"修改成功");
    }

    @Override
    public Result updateStatus(Integer deptId, Integer deptStatus) {

        if (deptStatus ==0){
            Dept dept = new Dept();
            dept.setDeptId(deptId);
            dept.setDeptStatus(1);
            int i = deptMapper.updateByPrimaryKeySelective(dept);
            return new Result(200,"修改状态成功(裁撤部门变正常)");
        }else{
            Dept dept1 = new Dept();
            dept1.setDeptId(deptId);
            dept1.setDeptStatus(0);
            int i = deptMapper.updateByPrimaryKeySelective(dept1);
            return new Result(200,"修改状态成功(正常变裁撤部门)");
        }

    }

    @Override
    public Result getOfficeName(Integer deptId) {

        List<String> strings = deptMapper.selectAllOfficeName(deptId);
        return new Result(200,"查询分支科室成功",strings);
    }


}